package com.tiancheng.trade.payment.util;

import com.tiancheng.trade.commom.core.enums.PaySceneEnum;
import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.commom.core.enums.PaymentWayEnum;
import com.tiancheng.trade.payment.enums.*;
import com.tiancheng.trade.payment.vo.admin.KeyValueVO;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DictUtil {

    private static final String businessTypeEnum = "businessType";
    private static final String paymentChannelEnum = "paymentChannel";
    private static final String flowStatusEnum = "flowStatus";
    private static final String paymentSubChannelEnum = "paymentSubChannel";
    private static final String paySceneStatusEnum = "paySceneStatus";

    private static Map<String, List<KeyValueVO>> map = new HashMap<>();

    public static Map<String, List<KeyValueVO>> getDict() {
        return map;
    }

    public static List<KeyValueVO> getDict(String dictType) {
        return map.get(dictType);
    }

    static {
        List<KeyValueVO> businessTypeEnum = Arrays.stream(BusinessTypeEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.businessTypeEnum, businessTypeEnum);

        List<KeyValueVO> paymentChannelEnum = Arrays.stream(PaymentChannelEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.paymentChannelEnum, paymentChannelEnum);

        List<KeyValueVO> paymentOrderPayStatusEnum = Arrays.stream(FlowStatusEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.flowStatusEnum, paymentOrderPayStatusEnum);

        List<KeyValueVO> paymentSubChannelEnum = Arrays.stream(PaymentWayEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.paymentSubChannelEnum, paymentSubChannelEnum);

        List<KeyValueVO> paySceneStatusEnum = Arrays.stream(PaySceneEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.paySceneStatusEnum, paySceneStatusEnum);
    }
}
